/*
 * @Content: 所有模块路由 => 基础API http://116.62.147.91:3040
 *
 * @Author: zhanghf
 */
const Router = require('koa-router')()
const user = require('../control/user')
/**
 * @api {post} /user/reg 用户注册
 * @apiName reg
 * @apiGroup user
 * @apiDescription 管理员添加用户
 * @apiParam (params) {String} username 用户名
 * @apiParam (params) {String} password 密码
 * @apiParam (params) {String} role 角色
 * @apiParam (params) {String} number 学号/工号
 *
 * @apiSuccessExample 成功
 * {
      "code": 1,
      "data": null,
      "msg":"注册成功"
  }
 *
 */
Router.post('/reg', user.reg)
/**
 * @api {post} /user/update 用户信息修改
 * @apiName update
 * @apiGroup user
 * @apiDescription 用户信息修改
 * @apiParam (params) {String} userId 用户id
 * @apiParam (params) {String} username 用户名
 * @apiParam (params) {String} password 密码
 * @apiParam (params) {String} role 角色
 * @apiParam (params) {String} number 学号/工号
 * 
 * @apiHeaderExample {json} Header:
 * {
 *    "Authorition": "Bearer xxxxxxxxxxxx(登陆时获取的token)"
 *  }
 *
 * @apiSuccessExample 成功
 * {
      "code": 1,
      "data": "修改成功",
      "msg": "请求成功"
  }
 *
 */
Router.post('/update', user.update)

/**
 * @api {post} /user/update 用户信息修改
 * @apiName update
 * @apiGroup user
 * @apiDescription 用户信息修改
 * @apiParam (params) {String} userId 用户id
 * @apiHeaderExample {json} Header:
 * {
 *    "Authorition": "Bearer xxxxxxxxxxxx(登陆时获取的token)"
 *  }
 *
 * @apiSuccessExample 成功
 * {
      "code": 1,
      "data": "删除成功",
      "msg": "请求成功"
  }
 *
 */
Router.post('/del', user.del)
/**
 * @api {post} /user/inquire 获取用户信息列表
 * @apiName inquire
 * @apiGroup user
 * @apiDescription 用户信息修改
 * @apiParam (params) {String} pageNum 分页开始页
 * @apiParam (params) {String} pageSize 分页单页数量
 * 
 * @apiHeaderExample {json} Header:
 * {
 *    "Authorition": "Bearer xxxxxxxxxxxx(登陆时获取的token)"
 *  }
 *
 * @apiSuccessExample 成功
 * {
    "code": 1,
    "data": {
    totalPage: 10,
      userLists: [
        {
          avatar: "/avatar/default.jpg",
          number: "0000",
          password: "admin",
          remark: "",
          role: "0",
          username: "admin",
          _id: "5caf045afaf2223691292cbf",
        }
      ]
  }
 *
 */

Router.post('/inquire', user.inquire)
/**
 * @api {post} /user/login 用户登陆
 * @apiName login
 * @apiGroup user
 * @apiDescription 用户登陆
 * @apiParam (params) {String} username 用户名
 * @apiParam (params) {String} password 密码
 *
 * @apiSuccessExample 成功
 * {
      code:1,
      data:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOiI1Y2FmMDQ1YWZhZjIyMjM2OTEyOTJjYmYiLCJyb2xlIjoiMCIsImlhdCI6MTU2MTI5MzUzMywiZXhwIjoxNTYxMjk3MTMzfQ.xM3c7ZWX4FAK-Yv2KRrCumIXCn9Pacfadx7caXaUcbg",
      msg:"登录成功"
  }
 * @apiErrorExample {json} 未登录
  {
      code:"000002"
      errMsg:"用户名或密码错误"
  }
 *
 */

Router.post('/login', user.login)

Router.get('/upload', user.upload)
/**
 * @api {get} /user/info 获取登陆用户信息
 * @apiName info
 * @apiGroup user
 * @apiDescription 获取登陆用户信息
 * 
 * @apiHeaderExample {json} Header:
 * {
 *    "Authorition": "Bearer xxxxxxxxxxxx(登陆时获取的token)"
 *  }
 *
 * @apiSuccessExample 成功
 * {
      code: 1,
      data:{
        avatar:"/avatar/default.jpg",
        number:"0000",
        password:"admin",
        remark:"",
        role:"0",
        username:"admin",
        _id:"5caf045afaf2223691292cbf"
      },
      msg:"请求成功"
 
  }
 *
 */
Router.get('/info', user.getinfo)

Router.post('/getUsersLists', user.getUsersLists)


module.exports = Router
